﻿/**  版本信息模板在安装目录下，可自行修改。
* T_ProductModel.cs
*
* 功 能： N/A
* 类 名： T_ProductModel
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2017/5/8 星期一 下午 10:35:02   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using SYDZ.WMS.DBUtility;
namespace WMSAML.Warehouse.DAL
{
	/// <summary>
	/// 数据访问类:T_ProductModel
	/// </summary>
	public partial class T_ProductModel
	{
		public T_ProductModel()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("Models_Id", "T_ProductModel"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int Models_Id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_ProductModel");
			strSql.Append(" where Models_Id=@Models_Id");
			SqlParameter[] parameters = {
					new SqlParameter("@Models_Id", SqlDbType.Int,4)
			};
			parameters[0].Value = Models_Id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(WMSAML.Warehouse.Model.T_ProductModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_ProductModel(");
			strSql.Append("Models_NO,Models_Name,Models_Fake,Models_Weight,Models_WeightMax,Models_WeightMin,Models_Width,Models_Height,Models_Highness,Models_Volume,Mark,Create_Time,Update_Time,Update_User_Id,BK01,BK02,BK03,BK04,BK05)");
			strSql.Append(" values (");
			strSql.Append("@Models_NO,@Models_Name,@Models_Fake,@Models_Weight,@Models_WeightMax,@Models_WeightMin,@Models_Width,@Models_Height,@Models_Highness,@Models_Volume,@Mark,@Create_Time,@Update_Time,@Update_User_Id,@BK01,@BK02,@BK03,@BK04,@BK05)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@Models_NO", SqlDbType.NVarChar,200),
					new SqlParameter("@Models_Name", SqlDbType.NVarChar,200),
					new SqlParameter("@Models_Fake", SqlDbType.NVarChar,200),
					new SqlParameter("@Models_Weight", SqlDbType.Decimal,9),
					new SqlParameter("@Models_WeightMax", SqlDbType.Decimal,9),
					new SqlParameter("@Models_WeightMin", SqlDbType.Decimal,9),
					new SqlParameter("@Models_Width", SqlDbType.Decimal,9),
					new SqlParameter("@Models_Height", SqlDbType.Decimal,9),
					new SqlParameter("@Models_Highness", SqlDbType.Decimal,9),
					new SqlParameter("@Models_Volume", SqlDbType.Decimal,9),
					new SqlParameter("@Mark", SqlDbType.NVarChar,-1),
					new SqlParameter("@Create_Time", SqlDbType.NVarChar,200),
					new SqlParameter("@Update_Time", SqlDbType.NVarChar,200),
					new SqlParameter("@Update_User_Id", SqlDbType.NVarChar,200),
					new SqlParameter("@BK01", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK02", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK03", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK04", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK05", SqlDbType.NVarChar,-1)};
			parameters[0].Value = model.Models_NO;
			parameters[1].Value = model.Models_Name;
			parameters[2].Value = model.Models_Fake;
			parameters[3].Value = model.Models_Weight;
			parameters[4].Value = model.Models_WeightMax;
			parameters[5].Value = model.Models_WeightMin;
			parameters[6].Value = model.Models_Width;
			parameters[7].Value = model.Models_Height;
			parameters[8].Value = model.Models_Highness;
			parameters[9].Value = model.Models_Volume;
			parameters[10].Value = model.Mark;
			parameters[11].Value = model.Create_Time;
			parameters[12].Value = model.Update_Time;
			parameters[13].Value = model.Update_User_Id;
			parameters[14].Value = model.BK01;
			parameters[15].Value = model.BK02;
			parameters[16].Value = model.BK03;
			parameters[17].Value = model.BK04;
			parameters[18].Value = model.BK05;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(WMSAML.Warehouse.Model.T_ProductModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_ProductModel set ");
			strSql.Append("Models_NO=@Models_NO,");
			strSql.Append("Models_Name=@Models_Name,");
			strSql.Append("Models_Fake=@Models_Fake,");
			strSql.Append("Models_Weight=@Models_Weight,");
			strSql.Append("Models_WeightMax=@Models_WeightMax,");
			strSql.Append("Models_WeightMin=@Models_WeightMin,");
			strSql.Append("Models_Width=@Models_Width,");
			strSql.Append("Models_Height=@Models_Height,");
			strSql.Append("Models_Highness=@Models_Highness,");
			strSql.Append("Models_Volume=@Models_Volume,");
			strSql.Append("Mark=@Mark,");
			strSql.Append("Create_Time=@Create_Time,");
			strSql.Append("Update_Time=@Update_Time,");
			strSql.Append("Update_User_Id=@Update_User_Id,");
			strSql.Append("BK01=@BK01,");
			strSql.Append("BK02=@BK02,");
			strSql.Append("BK03=@BK03,");
			strSql.Append("BK04=@BK04,");
			strSql.Append("BK05=@BK05");
			strSql.Append(" where Models_Id=@Models_Id");
			SqlParameter[] parameters = {
					new SqlParameter("@Models_NO", SqlDbType.NVarChar,200),
					new SqlParameter("@Models_Name", SqlDbType.NVarChar,200),
					new SqlParameter("@Models_Fake", SqlDbType.NVarChar,200),
					new SqlParameter("@Models_Weight", SqlDbType.Decimal,9),
					new SqlParameter("@Models_WeightMax", SqlDbType.Decimal,9),
					new SqlParameter("@Models_WeightMin", SqlDbType.Decimal,9),
					new SqlParameter("@Models_Width", SqlDbType.Decimal,9),
					new SqlParameter("@Models_Height", SqlDbType.Decimal,9),
					new SqlParameter("@Models_Highness", SqlDbType.Decimal,9),
					new SqlParameter("@Models_Volume", SqlDbType.Decimal,9),
					new SqlParameter("@Mark", SqlDbType.NVarChar,-1),
					new SqlParameter("@Create_Time", SqlDbType.NVarChar,200),
					new SqlParameter("@Update_Time", SqlDbType.NVarChar,200),
					new SqlParameter("@Update_User_Id", SqlDbType.NVarChar,200),
					new SqlParameter("@BK01", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK02", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK03", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK04", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK05", SqlDbType.NVarChar,-1),
					new SqlParameter("@Models_Id", SqlDbType.Int,4)};
			parameters[0].Value = model.Models_NO;
			parameters[1].Value = model.Models_Name;
			parameters[2].Value = model.Models_Fake;
			parameters[3].Value = model.Models_Weight;
			parameters[4].Value = model.Models_WeightMax;
			parameters[5].Value = model.Models_WeightMin;
			parameters[6].Value = model.Models_Width;
			parameters[7].Value = model.Models_Height;
			parameters[8].Value = model.Models_Highness;
			parameters[9].Value = model.Models_Volume;
			parameters[10].Value = model.Mark;
			parameters[11].Value = model.Create_Time;
			parameters[12].Value = model.Update_Time;
			parameters[13].Value = model.Update_User_Id;
			parameters[14].Value = model.BK01;
			parameters[15].Value = model.BK02;
			parameters[16].Value = model.BK03;
			parameters[17].Value = model.BK04;
			parameters[18].Value = model.BK05;
			parameters[19].Value = model.Models_Id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Models_Id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_ProductModel ");
			strSql.Append(" where Models_Id=@Models_Id");
			SqlParameter[] parameters = {
					new SqlParameter("@Models_Id", SqlDbType.Int,4)
			};
			parameters[0].Value = Models_Id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string Models_Idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_ProductModel ");
			strSql.Append(" where Models_Id in ("+Models_Idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public WMSAML.Warehouse.Model.T_ProductModel GetModel(int Models_Id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 Models_Id,Models_NO,Models_Name,Models_Fake,Models_Weight,Models_WeightMax,Models_WeightMin,Models_Width,Models_Height,Models_Highness,Models_Volume,Mark,Create_Time,Update_Time,Update_User_Id,BK01,BK02,BK03,BK04,BK05 from T_ProductModel ");
			strSql.Append(" where Models_Id=@Models_Id");
			SqlParameter[] parameters = {
					new SqlParameter("@Models_Id", SqlDbType.Int,4)
			};
			parameters[0].Value = Models_Id;

			WMSAML.Warehouse.Model.T_ProductModel model=new WMSAML.Warehouse.Model.T_ProductModel();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public WMSAML.Warehouse.Model.T_ProductModel DataRowToModel(DataRow row)
		{
			WMSAML.Warehouse.Model.T_ProductModel model=new WMSAML.Warehouse.Model.T_ProductModel();
			if (row != null)
			{
				if(row["Models_Id"]!=null && row["Models_Id"].ToString()!="")
				{
					model.Models_Id=int.Parse(row["Models_Id"].ToString());
				}
				if(row["Models_NO"]!=null)
				{
					model.Models_NO=row["Models_NO"].ToString();
				}
				if(row["Models_Name"]!=null)
				{
					model.Models_Name=row["Models_Name"].ToString();
				}
				if(row["Models_Fake"]!=null)
				{
					model.Models_Fake=row["Models_Fake"].ToString();
				}
				if(row["Models_Weight"]!=null && row["Models_Weight"].ToString()!="")
				{
					model.Models_Weight=decimal.Parse(row["Models_Weight"].ToString());
				}
				if(row["Models_WeightMax"]!=null && row["Models_WeightMax"].ToString()!="")
				{
					model.Models_WeightMax=decimal.Parse(row["Models_WeightMax"].ToString());
				}
				if(row["Models_WeightMin"]!=null && row["Models_WeightMin"].ToString()!="")
				{
					model.Models_WeightMin=decimal.Parse(row["Models_WeightMin"].ToString());
				}
				if(row["Models_Width"]!=null && row["Models_Width"].ToString()!="")
				{
					model.Models_Width=decimal.Parse(row["Models_Width"].ToString());
				}
				if(row["Models_Height"]!=null && row["Models_Height"].ToString()!="")
				{
					model.Models_Height=decimal.Parse(row["Models_Height"].ToString());
				}
				if(row["Models_Highness"]!=null && row["Models_Highness"].ToString()!="")
				{
					model.Models_Highness=decimal.Parse(row["Models_Highness"].ToString());
				}
				if(row["Models_Volume"]!=null && row["Models_Volume"].ToString()!="")
				{
					model.Models_Volume=decimal.Parse(row["Models_Volume"].ToString());
				}
				if(row["Mark"]!=null)
				{
					model.Mark=row["Mark"].ToString();
				}
				if(row["Create_Time"]!=null)
				{
					model.Create_Time=row["Create_Time"].ToString();
				}
				if(row["Update_Time"]!=null)
				{
					model.Update_Time=row["Update_Time"].ToString();
				}
				if(row["Update_User_Id"]!=null)
				{
					model.Update_User_Id=row["Update_User_Id"].ToString();
				}
				if(row["BK01"]!=null)
				{
					model.BK01=row["BK01"].ToString();
				}
				if(row["BK02"]!=null)
				{
					model.BK02=row["BK02"].ToString();
				}
				if(row["BK03"]!=null)
				{
					model.BK03=row["BK03"].ToString();
				}
				if(row["BK04"]!=null)
				{
					model.BK04=row["BK04"].ToString();
				}
				if(row["BK05"]!=null)
				{
					model.BK05=row["BK05"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Models_Id,Models_NO,Models_Name,Models_Fake,Models_Weight,Models_WeightMax,Models_WeightMin,Models_Width,Models_Height,Models_Highness,Models_Volume,Mark,Create_Time,Update_Time,Update_User_Id,BK01,BK02,BK03,BK04,BK05 ");
			strSql.Append(" FROM T_ProductModel ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" Models_Id,Models_NO,Models_Name,Models_Fake,Models_Weight,Models_WeightMax,Models_WeightMin,Models_Width,Models_Height,Models_Highness,Models_Volume,Mark,Create_Time,Update_Time,Update_User_Id,BK01,BK02,BK03,BK04,BK05 ");
			strSql.Append(" FROM T_ProductModel ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_ProductModel ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.Models_Id desc");
			}
			strSql.Append(")AS Row, T.*  from T_ProductModel T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "T_ProductModel";
			parameters[1].Value = "Models_Id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

